quote string values in empty assertion failures#1875
Open
Bojun-Vvibe wants to merge 1 commit intostretchr:masterfrom
Open
quote string values in empty assertion failures#1875Bojun-Vvibe wants to merge 1 commit intostretchr:masterfrom
Bojun-Vvibe wants to merge 1 commit intostretchr:masterfrom
Conversation
dolmen
requested changes
Apr 22, 2026
Collaborator
dolmen
left a comment
There was a problem hiding this comment.
Changes should happen in truncatingFormat.
Author
|
Thanks for the review @dolmen. To make sure I move this in the right direction — did you mean: (a) have |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repo: stretchr/testify (⭐ 23000)
Type: bugfix
Files changed: 2
Lines: +20/-22
What
This change updates
assert.Emptyandassert.NotEmptyto quote string values in failure messages, including aliased string types. The relatedassertpackage tests were updated so whitespace-only, newline-containing, and empty-string cases now assert against explicit, readable output like"\\n"and""instead of visually ambiguous raw text.Why
Current failure output for string values uses
%v, which makes empty strings and whitespace-heavy strings hard to distinguish from formatting noise. That weakens assertion diagnostics in exactly the cases where users need clarity. Quoting string values keeps behavior unchanged while making failures immediately understandable and resolves the existing TODO-marked test expectations around these messages.Testing
Ran
GOCACHE=$(pwd)/.gocache go test ./assert -run 'Test(Empty|NotEmpty)$'from the repo root. The targeted tests passed.Risk
Low / Message formatting only changes for string values in
EmptyandNotEmpty; assertion semantics are unchanged.